using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DialogueController : MonoBehaviour
{
   public DialogueData_SO dialogueDataSo;
   private AudioSource AudioSource;


   private void Awake()
   {
      AudioSource = GetComponent<AudioSource>();
   }

   public bool canTalk;

   private void OnTriggerEnter(Collider other)
   {
      if (other.CompareTag("Player"))
      {
         canTalk = true;
      }
   }

   private void OnTriggerExit(Collider other)
   {
      if (other.CompareTag("Player"))
      {
         DialogueManager.Instance.dialoguePanel.gameObject.SetActive(false);
         canTalk = false;
      }
   }

   private void Update()
   {
      if (canTalk && Input.GetKeyDown(KeyCode.F))
      {
         OpenDialogue();
      }
   }

   public void OpenDialogue()
   {
      //打开UI面板
      //传输对话的内容
      DialogueManager.Instance.updateDialogueData(dialogueDataSo);
      DialogueManager.Instance.updateDialougueUI(dialogueDataSo.DialogPieces[0]);
   }
}
